package cn.edu.sdjzu.xg23.kcsj01_backend.controller;


import cn.edu.sdjzu.xg23.kcsj01_backend.entity.Employee;
import cn.edu.sdjzu.xg23.kcsj01_backend.service.EmployeeService;
import cn.edu.sdjzu.xg23.kcsj01_backend.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @PostMapping("/employee")
    public Result addEmployee(@RequestBody Employee employee) {
        if (employeeService.addEmployee(employee)) {
            return Result.success("增加成功");
        } else {
            return Result.error("500", "增加失败");
        }
    }

    @PostMapping("/employees")
    public Result get(@RequestParam(defaultValue = "1") Integer pageNum,
                      @RequestParam(defaultValue = "10") Integer pageSize,
                      @RequestBody (required = false) Employee employee) {
        return Result.success(employeeService.get(pageNum,pageSize,employee));
    }



    @PostMapping("employees1")
    public Result save(@RequestBody Employee employee) {
        return Result.success(employeeService.save(employee));
    }
    @PutMapping("employees")
    public Result update(@RequestBody Employee employee) {
        return Result.success(employeeService.update(employee));
    }
    @DeleteMapping("employees/{id}")
    public Result delete(@PathVariable long id) {
        return Result.success(employeeService.delete(id));
    }




}
